package com.yaohe.consumer.network.msghandler.impl;

import java.util.ArrayList;

import org.apache.mina.core.session.IoSession;

import android.util.Log;

import com.yaohe.common.key.CouponId;
import com.yaohe.consumer.network.msghandler.MessageHandler;
import com.yaohe.consumer.service.YaoheService;
import com.yaohe.protocols.ProtocolProtos.Protocol;
import com.yaohe.protocols.ProtocolProtos.Protocol.IdList;

public class InfoQueryHandler implements MessageHandler{

	private static InfoQueryHandler infoQueryHandler = new InfoQueryHandler();
	
	public static InfoQueryHandler getHandler(){
		return infoQueryHandler;
	}
	
	public void handle(Protocol message, IoSession session) {
		// TODO Auto-generated method stub
		
		IdList lists = message.getMessage().getCouponQueryResponse().getIdList();
		//IdList to CouponList...
		ArrayList<CouponId>couponList  = new ArrayList<CouponId>();
		for(int i = 0; i < lists.getCouponIDCount(); i++){
			couponList.add(new CouponId(lists.getCouponID(i).toByteArray()));
		}
		YaoheService.dealWithInfoQuery(couponList);
	}

}
